import http from '@/utils/request'
import { api } from '@/api/api'
// 购物车相关请求

//jsdoc js文档注释
/**
 *
 * @param {string} userid
 * @param {string} proid
 * @param {string} num
 * @returns {promise}
 */
function cartAddReq(userid, proid, num) {
  //http函数返回的是什么？promsie对象

  // productSearch 把http函数调用以后promsie对象作为了返回值
  return http({
    method: 'post',
    url: api.addCartApi,
    data: { userid, proid, num },
  })
}

function cartListReq(userid) {
  return http({
    method: 'post',
    url: api.getCartListApi,
    data: { userid },
  })
}

function changeNumReq(cartid, num) {
  return http({
    method: 'post',
    url: api.postCartUpNumApi,
    data: { cartid, num },
  })
}
//单选
function checkReq(cartid, flag) {
  return http({
    method: 'post',
    url: api.postselectoneApi,
    data: { cartid, flag },
  })
}
//全选
function checkAllReq(userid, type) {
  return http({
    method: 'post',
    url: api.postselectallApi,
    data: { userid, type },
  })
}
//删除一个
function delReq(cartid) {
  return http({
    method: 'post',
    url: api.postCartRemoveApi,
    data: { cartid },
  })
}
//清空购物车
function delAllReq(userid) {
  return http({
    method: 'post',
    url: api.postremoveallApi,
    data: { userid },
  })
}

export { cartAddReq, cartListReq, changeNumReq, checkReq, delReq, delAllReq, checkAllReq }
